#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed
export DEB_BUILD_MAINT_OPTIONS=hardening=+all


NPROC := $(shell nproc 2> /dev/null || echo 1)

BUILDOPTS := $(EXTRA_BUILDOPTS) --with-qt6_client

%:
	dh $@ --with python3 --with systemd --without=build-stamp

override_dh_auto_clean:
	python3 setup.py clean

override_dh_auto_build:
	python3 -B setup.py build_ext $(BUILDOPTS) -j $(NPROC)
	python3 -B setup.py build $(BUILDOPTS)

override_dh_install:
	dh_movefiles
	dh_install

override_dh_auto_install:
	python3 -B setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb $(BUILDOPTS)

override_dh_installchangelogs:
	dh_installchangelogs docs/CHANGELOG.md

override_dh_shlibdeps:
	dh_shlibdeps -Xcodecs/ -Xx11 -Xgdk -Xgtk -Xbrotli/ -Xqrcode/ -Xproc_ -Xsd_listen
	dh_shlibdeps -Xnvidia/ -Xffmpeg/ -Xgstreamer/ -Xx264/ -Xx11 -Xgdk -Xgtk -Xbrotli/ -Xqrcode/ -Xproc_ -Xsd_listen -- -pcodecs
	dh_shlibdeps -Xnvidia/ -Xavif/ -Xcsc_cython/ -Xdrm/ -Xevdi/ -Xjpeg/ -Xlibyuv/ -Xspng/ -Xv4l2/ -Xvpx/ -Xwebp/ -Xx11 -Xgdk -Xgtk -Xbrotli/ -Xqrcode/ -Xproc_ -Xsd_listen -- -pcodecsextras
	dh_shlibdeps -Xcodecs/ -Xgdk -Xgtk -Xbrotli/ -Xqrcode/ -Xproc_ -Xsd_listen -- -px11
	dh_shlibdeps -Xcodecs/ -Xx11 -Xgdk -Xgtk -Xqrcode/ -Xproc_ -Xsd_listen -- -pbrotli
	dh_shlibdeps -Xcodecs/ -Xx11 -Xgdk -Xgtk -Xbrotli/ -Xproc_ -Xsd_listen -- -pqrcode
	dh_shlibdeps -Xcodecs/ -Xx11 -Xgdk -Xgtk -Xbrotli/ -Xqrcode/ -Xsd_listen -- -pproc

override_dh_systemd_enable:
	dh_systemd_enable --no-enable xpra-server.service
	dh_systemd_enable xpra-server.socket

#override_dh_systemd_start:
#	dh_systemd_start xpra.socket

override_dh_installman:
	mkdir -p debian/xpra-common/usr/share/man/man1 debian/xpra-client-gtk3/usr/share/man/man1
	cp fs/share/man/man1/xpra.1 debian/xpra-common/usr/share/man/man1/
	cp fs/share/man/man1/xpra_launcher.1 fs/share/man/man1/run_scaled.1 debian/xpra-client-gtk3/usr/share/man/man1/
	gzip -9 debian/xpra-*/usr/share/man/man1/*.1

override_dh_builddeb:
	dh_builddeb -- -Zxz

# Ubuntu messes up the cups backend permissions, fix it:
override_dh_fixperms:
	dh_fixperms --exclude xpraforwarder
